/**
 *  预警预报应用深化-污染源分析-排污大户分析
 *  Created by lins on 2018/7/16.
 */
'use strict';
angular.module("MetronicApp").directive('pollutionBar', function () {
    return {
        scope: {
            id: "@",
            data: "="
        },
        restrict: 'EA',
        template: '',
        replace: true,
        link: function ($scope, element, attrs, controller) {
            function getOption(data) {
                var option = {
                    title : {
                        text: '排污大户分析',
                        x:'center',
                        textStyle:{  //标题文字设置
                            fontSize: '20',
                            fontWeight: 'bold',
                            color: '#5AB1EF'
                        }
                    },
                    tooltip : {
                        trigger: 'axis',
                        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    legend: {
                        x : 'center',
                        y : 'bottom',
                        itemStyle: {
                            normal: {
                                //柱形图圆角，初始化效果
                                barBorderRadius:[5, 5, 5, 5]
                            }
                        },
                        data: ['钢铁行业', '水泥行业','电力行业','玻璃行业','化工行业','石油行业','其他行业']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '50px',
                        containLabel: true
                    },
                    xAxis:  {
                        type: 'category',
                        data: ['石家庄市','唐山市','秦皇岛市','邯郸市','邢台市','保定市','张家口市','承德市','沧州市','廊坊市','衡水市']
                    },
                    yAxis: {
                        type: 'value',
                        min: 0,
                        max: 500,
                        interval: 100,
                    },
                    series: [
                        {
                            name: '钢铁行业',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {
                                normal: {
                                    //柱形图圆角，初始化效果
                                    barBorderRadius:[5, 5, 5, 5],
                                    color: '#2EC7C9'

                                }
                            },
                            data: [50, 80, 40, 20, 10, 50, 60,80,50,40,70]
                        },
                        {
                            name: '水泥行业',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {
                                normal: {
                                    //柱形图圆角，初始化效果
                                    barBorderRadius:[5, 5, 5, 5],
                                    color: '#B6A2DE'

                                }
                            },
                            data: [90, 20, 40, 100, 10, 20, 20,20,80,80,30]
                        },
                        {
                            name: '电力行业',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {
                                normal: {
                                    //柱形图圆角，初始化效果
                                    barBorderRadius:[5, 5, 5, 5],
                                    color: '#5AB1EF'

                                }
                            },
                            data: [110,40,10,20,80,80,30,30,70,10,90]
                        },
                        {
                            name: '玻璃行业',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {
                                normal: {
                                    //柱形图圆角，初始化效果
                                    barBorderRadius:[5, 5, 5, 5],
                                    color: '#FFB980'

                                }
                            },
                            data: [100,10,40,40,40,5,20,80,90,15,90]
                        },
                        {
                            name: '化工行业',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {
                                normal: {
                                    //柱形图圆角，初始化效果
                                    barBorderRadius:[5, 5, 5, 5],
                                    color: '#D8807A'

                                }
                            },
                            data: [10, 20, 40, 5, 10, 110, 40,5,40,30,30]
                        },
                        {
                            name: '石油行业',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {
                                normal: {
                                    //柱形图圆角，初始化效果
                                    barBorderRadius:[5, 5, 5, 5],
                                    color: '#8D98B3'

                                }
                            },
                            data: [30,10,40,80,20,110,20,10,50,5,40]
                        },
                        {
                            name: '其他行业',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {
                                normal: {
                                    //柱形图圆角，初始化效果
                                    barBorderRadius:[5, 5, 5, 5],
                                    color: '#E5CF0D'

                                }
                            },
                            data: [10,10,40,60,60,60,20,40,20,70,20]

                        },
                    ]
                };
                return option;
            }

            var myChart = echarts.init(document.getElementById('third'), 'macarons');
            myChart.setOption(getOption($scope.data));

            $scope.$watch('data', function (newVal, oldVal) {
                myChart.setOption(getOption(newVal));
            });
        }
    };
});
